﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model;
using DataAccess;
using Model.EntityModel;

namespace Project
{
    /// <summary>
    /// Lógica de interacción para AudiencesOfComplaint.xaml
    /// </summary>
    public partial class AudiencesOfComplaint : UserControl
    {
        public List<AudienceClass> allAudiences;
        public AudiencesOfComplaint()
        {
            InitializeComponent();
        }

        public AudiencesOfComplaint(long idcomp )
        {
            InitializeComponent();
            UIWindowManager.SetWindowTitle(this, "Brigada De Protección a la Familia - AudiencesOfComplaint");
            Complaint comp = ComplaintDataAccess.GetComplaintById(idcomp);
            fillInterface(comp);
            if (UserControllerAndDataAccess.IsUserLogged())
            {
                if (UserControllerAndDataAccess.IsDirectorLogged)
                {
                    Modify.Visibility = Visibility.Collapsed;
                }
            }
        }

        public void fillInterface(Complaint comp)
        {
            Model.EntityModel.Actor Denouncer;
            Model.EntityModel.Actor Agressor;
            /*Functionary emp;
            string name;*/

            lbCase.Content = comp.Id;
            lblNatFact.Content = comp.IncidentNature;
            lblPlace.Content = comp.IncidentPlace;
            
            Denouncer = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Denunciante", comp.Id);
            lblNameDenouncer.Content = Denouncer.Person.Name;
            lblPaternDenouncer.Content = Denouncer.Person.PaternalName;
            if (!String.IsNullOrEmpty(Denouncer.Person.MaternalName))
                lblMaternDenouncer.Content = Denouncer.Person.MaternalName;

            Agressor = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Agresor", comp.Id);
            lblNameDenounced.Content = Agressor.Person.Name;
            lblPaternDenounced.Content = Agressor.Person.PaternalName;
            if (!String.IsNullOrEmpty(Agressor.Person.MaternalName))
                lblMaternDenounced.Content = Agressor.Person.MaternalName;
            allAudiences = DataBaseAccess.GetAllAudiences(comp.Id);
            foreach (AudienceClass a in allAudiences)
            {
                /*emp = DataBaseAccess.ReadEmployee(a.CiEmployee);
                name = emp.Name + emp.PaternalName;
                if (!String.IsNullOrEmpty(emp.MaternalName))
                    name += emp.MaternalName;*/
                ListAudiences.Items.Add(a.Date.ToShortDateString() + " " + a.Time);
            }
        }

        private void Modify_Click(object sender, RoutedEventArgs e)
        {
            if (ListAudiences.SelectedIndex != -1)
            {
                Content.Children.Clear();
                Content.Children.Add(new RegisterAudience(allAudiences[ListAudiences.SelectedIndex]));
            }
            else
                MessageBox.Show("Seleccione una audiencia");
        }

        private void View_Click(object sender, RoutedEventArgs e)
        {
            if (ListAudiences.SelectedIndex != -1)
            {
                Content.Children.Clear();
                Content.Children.Add(new ViewAudience(allAudiences[ListAudiences.SelectedIndex]));
            }
            else
                MessageBox.Show("Seleccione una audiencia");
        }
    }
}
